<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBClientLoader
{

	function &getManager($controller, $setting) {
		
		$file_views = array('files', 'getfile');
		@$view = $_GET['View'];
		
		require_once $controller->working_dir . 'KBClientModel_common.php';
		
		if(in_array($view, $file_views)) {
					
			require_once APP_EXTRA_MODULE_DIR . 'file/client/inc/KBClientFileModel.php';
			require_once APP_EXTRA_MODULE_DIR . 'file/client/inc/KBClientFileView.php';
			require_once APP_EXTRA_MODULE_DIR . 'file/client/inc/default/KBClientFileModel_common.php';
			require_once APP_EXTRA_MODULE_DIR . 'file/client/inc/default/KBClientFileView_common.php';
			
			$manager = &new KBClientFileModel_common;
			$manager->setting = array_merge($setting, KBClientModel::getSettings(200));
			$manager->setCustomSettings();
			
		} else {
		
			$manager = &new KBClientModel_common;
			$manager->setting = &$setting;
			$manager->setCustomSettings();
		}
		$auth = &new AuthPriv();
		$manager->is_registered = $auth->isAuth();
        if($manager->is_registered) {
            $manager->user_id = $auth->getUserId();
            $manager->user_role_id = $auth->getRoleId();
        }
		
		
		$manager->setCategories();
		$manager->use_registration = $manager->isUseRegistration();
		//echo "<pre>"; print_r($manager->setting); echo "</pre>";		
		//echo "<pre>"; print_r($manager->categories); echo "</pre>";	
		
		return $manager;
	}


	function &getView(&$controller, $manager) {
				
		require_once $controller->working_dir . 'KBClientView_common.php';
		require_once $controller->working_dir . 'KBClientAction_common.php';
		
		
		$actions = array('entry', 'glossary', 'comment', 'contact', 'send', 'search', 
						 'register', 'member', 'confirm', 'login', 'logout', 'password',
						 'success_go', 'print', 'file');
		
		//$suffics = ($view_id) ? $view_id : 'index';
		$suffics = (in_array($controller->view_id, $actions)) ?  $controller->view_id : 'default';
		$action_class = 'KBClientAction_' . $suffics;
		$action_file  = 'KBClientAction_' . $suffics . '.php';
		
		$file = $controller->working_dir . 'action/' . $action_file;
		if(!file_exists($file)) {
			$file = $controller->default_working_dir . 'action/' . $action_file;
		}
		
		require_once($file);
		
		$action = &new $action_class;
		$action->setVars($controller, $manager);
		$action->checkAuth($controller, $manager);
		return $action->execute($controller, $manager);
 	}
}
?>